# 第一阶段：构建环境
FROM python:3.10.16-slim as builder

WORKDIR /app
COPY requirements.txt .
RUN pip install --user -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/

# 第二阶段：运行环境
FROM python:3.10.16-slim

WORKDIR /app
# 从builder阶段复制已安装的Python包
COPY --from=builder /root/.local /root/.local
COPY . .

# 确保脚本可执行
ENV PATH=/root/.local/bin:$PATH
ENV FLASK_APP=app.py

# 开放端口
EXPOSE 4600

# 运行Flask（生产环境建议用gunicorn）
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "4", "app:app"]
